<?php
// [ 判断是否为前端页面 ]
$path_info = $_SERVER['PATH_INFO'];
if (substr($path_info, -5) == '.html') {
    $file_path = 'rd' . $path_info;
    if (file_exists($file_path)) {
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
            $html = file_get_contents($file_path);
            preg_match_all('/<title>(.*?)<\/title>/i', $html, $match_title);
            preg_match_all('/href="(.*?\.css)"/i', $html, $match_css);
            preg_match_all('/src="(.*?\.js)"/i', $html, $match_js);
            preg_match_all('/<script>(.*?)<\/script>/is', $html, $match_script);
            $ret = [
                'css' => $match_css[1],
                'js' => $match_js[1],
                'title' => $match_title[1][0],
                'script' => preg_replace("/\s/", '', $match_script[0]),
            ];
            echo json_encode($ret, JSON_UNESCAPED_UNICODE);
        } else {
            require($file_path);
        }
    } else {
        header('HTTP/1.0 404 Not Found');
        die("File {$path_info} not exist!");
    }
    die();
}